package test.tcp.one2many;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class ManyClient {
	public static void main(String args[]) {
		try {
			Socket socket = new Socket("localhost", 12345);

			// 输入输出流
			BufferedReader sin = new BufferedReader(new InputStreamReader(
					System.in));
			BufferedReader is = new BufferedReader(new InputStreamReader(socket
					.getInputStream()));
			PrintWriter os = new PrintWriter(socket.getOutputStream());
			
			// 循环读取键盘输入
			String readline;
			while ( (readline=sin.readLine()) != null) {
				os.println(readline);
				os.flush();
				// 读取服务端回复
				String responseline = is.readLine();
				System.out.println("收到回复：" + responseline);
			}

			// 关闭输入输出流
			is.close();
			os.close();

			// 关闭客户端
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
